package com.ss.android.newmedia.f;

import android.app.Dialog;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bytedance.common.utility.Logger;
import com.ss.android.action.ActionThread;
import com.ss.android.article.browser.R;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.dialog.AlertDialog;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.image.loader.ImageLoader;
import com.ss.android.newmedia.a.WeakDialogListener;
import com.ss.android.newmedia.a.DialogListener;

import org.json.JSONArray;
import org.json.JSONObject;

public final class a {
    public int a;
    public long b;
    public String c;
    public boolean e;
    public boolean f;
    int d;
    private String g;
    private String h;
    private int i;
    private String[] j;
    private String[] k;
    private DialogListener l;
    private DialogListener m;

    public a() {

        this.f = false;
    }

    public final Dialog a(Context arg11, ImageLoader arg12, LayoutInflater arg13) {
        String v1;
        Dialog v0 = null;
        int v5 = 2;
        Dialog v2 = null;
        if (arg11 == null) {
            v0 = v2;
            return v0;
        }

        if (!this.f) {
            Logger.w("Alert", "try to show invalid alert");
            return v2;
        }

        if (this.j == null || this.k == null || this.j.length <= 0 || this.k.length <= 0 || this.j.length != this.k.length) {
            v0 = v2;
        } else if (!NetworkUtils.isNetworkAvailable(arg11)) {
            v0 = v2;
        } else {
            if (this.i == 0) {
                try {
                    Object v0_2 = arg11.getSystemService(Context.TELEPHONY_SERVICE);
                    v1 = ((TelephonyManager) v0_2).getNetworkOperator();
                    if (NetworkUtils.isWifi(arg11)) {
//                    goto label_56;
                    } else if (((TelephonyManager) v0_2).getPhoneType() != 1) {
//                    goto label_56;
                    } else if (!"46000".equals(v1) && !"46002".equals(v1) && !"46007".equals(v1)) {
//                    goto label_56;
                    } else {
                        v0 = v2;
                    }
                } catch (Exception v0_1) {
//                goto label_56;
                }
            }
            label_56:
            if (android.support.design.a.isTextEmpty(this.c)) {
                AlertDialog.Builder v0_3 = com.ss.android.j.b.createDialogBuilder(arg11);
                v0_3.setMessage(this.g);
                int v1_1 = this.j.length;
                v0_3.setPositiveButton(this.j[0], new e(this, arg11));
                if (v1_1 > v5) {
                    v1 = this.j[1];
                    f v3 = new f(this, arg11);
                    v0_3.alertParams.mNeutralButtonText = v1;
                    v0_3.alertParams.mNeutralButtonListener = v3;
                    v0_3.setNegativeButton(this.j[v5], new g(this, arg11));
                } else if (v1_1 > 1) {
                    v0_3.setNegativeButton(this.j[1], new h(this, arg11));
                }

                this.l = new i(this, arg11);
                v0_3.setOnCancelListener(new WeakDialogListener(this.l));
                AlertDialog v0_4 = v0_3.create();
            } else {
                if (this.d >= this.j.length) {
                    v0 = v2;
//                    goto label_91;
                } else {
                    a$a v3_1 = new a$a(arg11);
                    View v4 = arg13.inflate(com.ss.android.article.browser.R.layout.ae, null, false);
                    View v0_5 = v4.findViewById(com.ss.android.article.browser.R.id.iz);
                    View v5_1 = v4.findViewById(com.ss.android.article.browser.R.id.cancel_btn);
                    View v1_2 = v4.findViewById(com.ss.android.article.browser.R.id.j0);
                    ((TextView) v1_2).setText(this.j[this.d]);
                    ((TextView) v1_2).setOnClickListener(new com.ss.android.newmedia.f.b(this, v3_1, arg11));
                    v5_1.setOnClickListener(new com.ss.android.newmedia.f.c(v3_1));
                    this.m = new com.ss.android.newmedia.f.d(this, arg11);
                    v3_1.setOnCancelListener(new WeakDialogListener(this.m));
                    arg12.a(((ImageView) v0_5), this.c, null);
                    v3_1.setContentView(v4);
                    v0 = v3_1;
                }
            }

            label_91:
            if ((((AlertDialog) v0)) == null) {
                return v2;
            }

            this.a(arg11, -2);
            v0.show();
            v0.setCanceledOnTouchOutside(false);
            v0.setCancelable(true);
        }

        return v0;
    }

    final void a(Context arg7, int arg8) {
        if ((this.f) && arg7 != null) {
            int v2 = this.k.length;
            if (arg8 == -1) {
                MobClickCombiner.onEvent(arg7, "appalert_cancel", this.k[0]);
                new ActionThread(arg7, this.b, 0).start();
            } else if (arg8 >= 0 && arg8 < this.k.length) {
                String v1 = this.k[arg8];
                int v3 = arg8 + 1;
                String v0 = android.support.design.a.isTextEmpty(v1) ? this.k[0] : v1;
                MobClickCombiner.onEvent(arg7, "appalert_" + v2 + "_" + v3, v0);
                new ActionThread(arg7, this.b, v3).start();
                if (android.support.design.a.isTextEmpty(v1)) {
                    return;
                }

                ToolUtils.runApplication(arg7, this.h, v1);
            }
        }
    }

    public final boolean a(JSONObject arg10) {
        int v2 = 3;
        boolean v0 = false;
        if (this.f) {
            Logger.w("Alert", "try to re-decode an valid alert");
            return v0;
        }

        try {
            this.g = arg10.optString("content", null);
            if (android.support.design.a.isTextEmpty(this.g)) {
                return v0;
            }

            this.a = arg10.optInt("latency_seconds", -1);
            if (this.a < 0) {
                return v0;
            }

            this.b = arg10.optLong("rule_id", -1);
            if (this.b <= 0) {
                return v0;
            }

            this.h = arg10.optString("package", null);
            this.i = arg10.optInt("mobile_alert", 1);
            JSONArray v4 = arg10.optJSONArray("button_list");
            if (v4 == null) {
                return v0;
            }

            int v3 = v4.length();
            if (v3 <= 0) {
                return v0;
            }

            if (v3 > v2) {
                v3 = v2;
            }

            this.j = new String[v3];
            this.k = new String[v3];
            for (v2 = 0; v2 < v3; ++v2) {
                JSONObject v5 = v4.getJSONObject(v2);
                this.j[v2] = v5.optString("text", "");
                this.k[v2] = v5.optString("action_url", "");
            }

            this.c = arg10.optString("image");
            this.d = arg10.optInt("expected_index");
            this.f = true;
            this.e = false;
            v0 = true;
        } catch (Exception v1) {
        }

        return v0;
    }

    final class a$a extends Dialog {
        public a$a(Context arg2) {
            super(arg2, R.style.j8);
        }
    }
}

